﻿@model AuditModel.Score

@{
    ViewBag.Title = AuditResources.UI.PageTitle;
    Layout = "~/Views/Shared/ExpertJudge/_ExpertJudgeLayout.cshtml";
    AuditModel.Archive archive = (AuditModel.Archive)ViewBag.Archive;
    bool canscore = (bool)ViewBag.CanScore;
    AuditModel.ScorePercentage sp = (AuditModel.ScorePercentage)ViewBag.ScorePercentage;
    string _returnaction = ViewBag.ReturnAction;
}

<h2>@AuditResources.Score.ObjectName</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    var IsMaterialScoreValidated = true;
    var IsInstructionScoreValidated = true;
    var IsDefenseScoreValidated = true;
    var IsOthersScoreValidated = true;

    $(function () {
        $('#MaterialScore').blur(
        function () {
            //alert($(this).val());
            //alert($('#PercentofMaterial').html());
            if (parseFloat($(this).val()) > parseFloat($('#PercentofMaterial').html())) {
                $(this).addClass("input-validation-error");
                $('#MaterialError').html("得分超过权重限制");
                IsMaterialScoreValidated = false;
            }
            else {
                $(this).removeClass("input-validation-error");
                $('#MaterialError').html("");
                IsMaterialScoreValidated = true;
            }
        }
        );
        $('#InstructionScore').blur(
        function () {
            //alert($(this).val());
            //alert($('#PercentofInstruction').html());
            if (parseFloat($(this).val()) > parseFloat($('#PercentofInstruction').html())) {
                $(this).addClass("input-validation-error");
                $('#InstructionError').html("得分超过权重限制");
                IsInstructionScoreValidated = false;
            }
            else {
                $(this).removeClass("input-validation-error");
                $('#InstructionError').html("");
                IsInstructionScoreValidated = true;
            }
        }
        );
        $('#DefenseScore').blur(
        function () {
            //alert($(this).val());
            //alert($('#PercentofDefense').html());
            if (parseFloat($(this).val()) > parseFloat($('#PercentofDefense').html())) {
                $(this).addClass("input-validation-error");
                $('#DefenseError').html("得分超过权重限制");
                IsDefenseScoreValidated = false;
            }
            else {
                $(this).removeClass("input-validation-error");
                $('#DefenseError').html("");
                IsDefenseScoreValidated = true;
            }
        }
        );
        $('#OtherScore').blur(
        function () {
            //alert($(this).val());
            //alert($('#PercentofOthers').html());
            if (parseFloat($(this).val()) > parseFloat($('#PercentofOthers').html())) {
                $(this).addClass("input-validation-error");
                $('#OthersError').html("得分超过权重限制");
                IsOthersScoreValidated = false;
            }
            else {
                $(this).removeClass("input-validation-error");
                $('#OthersError').html("");
                IsOthersScoreValidated = true;
            }
        }
        );

        $('form').submit(
        function () {
            //alert($('input').hasClass('input-validation-error'));
            if (!(IsMaterialScoreValidated && IsDefenseScoreValidated && IsInstructionScoreValidated && IsOthersScoreValidated)) {
                return false;
            }
        }
        );

    });
</script>

@using (Html.BeginForm("Create", "Score", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)

@Html.Partial("_ArchiveDetailsSimple", archive)
        
       
        <fieldset>
        <legend>@AuditResources.Score.ObjectName</legend>
     @if (canscore)
     {
        <div class="editor-label">
            @AuditResources.Score.MaterialScore
        </div>
        <div class="editor-field">
            @Html.TextBox("MaterialScore", Model.MaterialScore.Value.ToString())<text>(<span id="PercentofMaterial">@sp.PercentofMaterial</span>)</text><span id="MaterialError" class="field-validation-error"></span>
            @Html.ValidationMessageFor(model => model.MaterialScore)
        </div>

        <div class="editor-label">
            @AuditResources.Score.InstructionScore
        </div>
        <div class="editor-field">
        @Html.TextBox("InstructionScore", Model.InstructionScore.Value.ToString())<text>(<span id="PercentofInstruction">@sp.PercentofInstruction</span>)</text><span id="InstructionError" class="field-validation-error"></span>
            @Html.ValidationMessageFor(model => model.InstructionScore)
        </div>

        <div class="editor-label">
            @AuditResources.Score.DefenseScore
        </div>
        <div class="editor-field">
        @Html.TextBox("DefenseScore", Model.DefenseScore.Value.ToString())<text>(<span id="PercentofDefense">@sp.PercentofDefense</span>)</text><span id="DefenseError" class="field-validation-error"></span>
            @Html.ValidationMessageFor(model => model.DefenseScore)
        </div>

        <div class="editor-label">
            @AuditResources.Score.OtherScore
        </div>
        <div class="editor-field">
        @Html.TextBox("OtherScore", Model.OtherScore.Value.ToString())<text>(<span id="PercentofOthers">@sp.PercentofOthers</span>)</text><span id="OthersError" class="field-validation-error"></span>
            @Html.ValidationMessageFor(model => model.OtherScore)
        </div>

        <div class="editor-label">
            @AuditResources.Score.Comment
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Comment, new { style = "width:500px" })
            @Html.ValidationMessageFor(model => model.Comment)
        </div>

        <div class="editor-label">
            @AuditResources.Score.CommentFile
        </div>
        <div class="editor-field">
        @if (string.IsNullOrEmpty(Model.CommentFile))
        {
            <text>无</text>
        }
        else
        {
            @Html.ActionLink(Model.CommentFile, "GetCommentFile", "DownloadManager", new { serialnumber = Model.ExpertJudgeSerialNumber, archiveid = Model.ArchiveID },null)
        }
          <input type="file" name="comment" id="comment" />
            @Html.HiddenFor(mode=>Model.CommentFile)
            @Html.ValidationMessageFor(model => model.CommentFile)
        </div>
        @Html.Hidden("SubmitTime", DateTime.Now)
        @Html.HiddenFor(model => model.ExpertJudgeSerialNumber)
        @Html.HiddenFor(model => model.ArchiveID)
        
     }
     else
     {
            <h3>档案目前不能评分！</h3>
            <h3>@ViewBag.ScorePeriod</h3>
     }
    </fieldset>

<div>
    @if (canscore)
    {
        <input type="submit" value="@AuditResources.UI.Save" />            
    }
    @Html.ActionLink(@AuditResources.UI.BackToList, _returnaction, "PW", null, new { @class = "button" })<br />
    @Html.ValidationMessageFor(model => model.ID)
</div>
    
}
